/*    */ package com.slim.daoimpl;
/*    */ 
/*    */ import java.util.List;

import javax.persistence.Table;

import org.appfuse.model.User;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Repository;

import com.slim.dao.UserDaoService;
/*    */ 
/*    */ @Repository
/*    */ public class UserDaoServiceImpl extends GenericDaoHibernate<User, Long>
/*    */   implements UserDaoService
/*    */ {
/*    */   public UserDaoServiceImpl()
/*    */   {
/* 33 */     super(User.class);
/*    */   }
/*    */ 
/*    */   public List<User> getUsers()
/*    */   {
/* 41 */     return getHibernateTemplate().find("from User u order by upper(u.username)");
/*    */   }
/*    */ 
/*    */   public User saveUser(User user)
/*    */   {
/* 48 */     if (this.log.isDebugEnabled()) {
/* 49 */       this.log.debug("user's id: " + user.getId());
/*    */     }
/* 51 */     getHibernateTemplate().saveOrUpdate(user);
/*    */ 
/* 53 */     getHibernateTemplate().flush();
/* 54 */     return user;
/*    */   }
/*    */ 
/*    */   public User save(User user)
/*    */   {
/* 67 */     return saveUser(user);
/*    */   }
/*    */ 
/*    */   public UserDetails loadUserByUsername(String username)
/*    */     throws UsernameNotFoundException
/*    */   {
/* 74 */     List users = getHibernateTemplate().find("from User where username=?", username);
/* 75 */     if ((users == null) || (users.isEmpty())) {
/* 76 */       throw new UsernameNotFoundException("user '" + username + "' not found...");
/*    */     }
/* 78 */     return (UserDetails)users.get(0);
/*    */   }
/*    */ 
/*    */   public String getUserPassword(String username)
/*    */   {
/* 86 */     SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(SessionFactoryUtils.getDataSource(getSessionFactory()));
/*    */ 
/* 88 */     Table table = (Table)AnnotationUtils.findAnnotation(User.class, Table.class);
/* 89 */     return (String)jdbcTemplate.queryForObject("select password from " + table.name() + " where username=?", String.class, new Object[] { username });
/*    */   }
/*    */ }

/* Location:           C:\.m2\repository\org\appfuse\appfuse-hibernate\2.1.0\
 * Qualified Name:     org.appfuse.dao.hibernate.UserDaoHibernate
 * JD-Core Version:    0.6.0
 */